package com.zhan.ielts.dao.impl;

import java.util.List;
import java.util.Map;

import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Repository;

import com.zhan.frame.core.dao.impl.BaseDaoImpl;
import com.zhan.frame.core.exception.DaoException;
import com.zhan.frame.core.utils.BeanUtils;
import com.zhan.ielts.dao.ParagraphDao;
import com.zhan.ielts.domain.Paragraph;
import com.zhan.ielts.domain.query.ParagraphQuery;
import com.zhan.ielts.domain.vo.ParagraphVo;

@Repository
public class ParagraphDaoImpl extends BaseDaoImpl<Paragraph> implements ParagraphDao {

	@Override
	public List<String> selectArticleType(Paragraph query) {
		try {
			Map<String, Object> params = BeanUtils.toMap(query);
			return sqlSessionTemplate.selectList(getSqlName("selectArticleType"), params);
		} catch (Exception e) {
			throw new DaoException(String.format("查询type出错！语句：%s", getSqlName("selectArticleType")), e);
		}

	}

	@Override
	public List<Integer> selectBookNo(Paragraph query) {
		try {
			Map<String, Object> params = BeanUtils.toMap(query);
			return sqlSessionTemplate.selectList(getSqlName("selectBookNo"), params);
		} catch (Exception e) {
			throw new DaoException(String.format("查询type出错！语句：%s", getSqlName("selectBookNo")), e);
		}
	}

	@Override
	public List<Integer> selectPaperNo(Paragraph query) {
		try {
			Map<String, Object> params = BeanUtils.toMap(query);
			return sqlSessionTemplate.selectList(getSqlName("selectPaperNo"), params);
		} catch (Exception e) {
			throw new DaoException(String.format("查询type出错！语句：%s", getSqlName("selectPaperNo")), e);
		}
	}

	@Override
	public List<Integer> selectPassageNo(Paragraph query) {
		try {
			Map<String, Object> params = BeanUtils.toMap(query);
			return sqlSessionTemplate.selectList(getSqlName("selectPassageNo"), params);
		} catch (Exception e) {
			throw new DaoException(String.format("查询type出错！语句：%s", getSqlName("selectPassageNo")), e);
		}
	}

	@Override
	public List<Integer> selectParagraphNo(Paragraph query) {
		try {
			Map<String, Object> params = BeanUtils.toMap(query);
			return sqlSessionTemplate.selectList(getSqlName("selectParagraphNo"), params);
		} catch (Exception e) {
			throw new DaoException(String.format("查询type出错！语句：%s", getSqlName("selectParagraphNo")), e);
		}
	}

	@Override
	public PageImpl<ParagraphVo> selectPageListCustom(ParagraphQuery query, Pageable pageable) {
		try {
			List<ParagraphVo> contentList = sqlSessionTemplate.selectList(getSqlName("selectCustom"),
					getParams(query, pageable));
			return new PageImpl<ParagraphVo>(contentList, pageable, this.selectCount(query));
		} catch (Exception e) {
			throw new DaoException(String.format("根据分页对象查询列表出错！语句:%s", getSqlName("selectCustom")), e);
		}
	}

	@Override
	public List<Paragraph> selectSubtypePassage(ParagraphVo entity) {
		try {
			Map<String, Object> params = BeanUtils.toMap(entity);
			return sqlSessionTemplate.selectList(getSqlName("selectSubtypePassage"), params);
		} catch (Exception e) {
			throw new DaoException(String.format("查询对象列表出错！语句：%s", getSqlName("selectSubtypePassage")), e);
		}
	}

	@Override
	public List<ParagraphVo> selectBySeqNo(ParagraphVo entity) {
		try {
			Map<String, Object> params = BeanUtils.toMap(entity);
			return sqlSessionTemplate.selectList(getSqlName("selectBySeqNo"), params);
		} catch (Exception e) {
			throw new DaoException(String.format("查询对象列表出错！语句：%s", getSqlName("selectBySeqNo")), e);
		}
	}

	@Override
	public List<Paragraph> selectByFixedConditions(ParagraphVo entity) {
		try {
			Map<String, Object> params = BeanUtils.toMap(entity);
			return sqlSessionTemplate.selectList(getSqlName("selectByFixedConditions"), params);
		} catch (Exception e) {
			throw new DaoException(String.format("查询对象列表出错！语句：%s", getSqlName("selectByFixedConditions")), e);
		}
	}

	@Override
	public void oneKeyUpdate() {
		try {
			Map<String, Object> params = BeanUtils.toMap(new ParagraphVo());
			sqlSessionTemplate.selectList(getSqlName("oneKeyUpdate"), params);
		} catch (Exception e) {
			throw new DaoException(String.format("查询type出错！语句：%s", getSqlName("oneKeyUpdate")), e);
		}
	}
}
